package com.sali.排序.raw;

import java.util.Arrays;

/**
 * @description:
 * @author: sali
 * @date: 2025/9/14 下午3:28.
 * @version: 1.0
 */
public class raw1_选择排序 {

    public static void main(String[] args) {
        int[] arr = new int[]{5, 4, 2, 3, 1};
        System.out.println(Arrays.toString(myGetRes(arr)));
    }

    private static int[] myGetRes(int[] arr) {
        int sortIndex = 0;
        while ( sortIndex < arr.length ) {
            int minIndex = sortIndex;
            for ( int i = sortIndex + 1; i < arr.length; i++ ) {
                if ( arr[i] < arr[minIndex] ) {
                    minIndex = i;
                }
            }
            // 换位置
            int temp = arr[minIndex];
            arr[minIndex] = arr[sortIndex];
            arr[sortIndex] = temp;
            sortIndex++;
        }
        return arr;
    }

}
